<?php
class newreply_Model extends GlobalModel {
	public function newReply ($data=array()) {
		$text = mysql_real_escape_string($data['text']);
		$author = $data['user'];
		$time = time();
		$status = '1';
		$did = (int) $data['discussion_id'];
		
		$sql = "INSERT INTO `xine_replys` SET
				`author`='$author',
				`text`='$text',
				`time`='$time',
				`discussion_id`='$did',
				`active`='1',
				`discussion_starter`='1'
		";
		
		if(mysql_query($sql)) {
			$id = mysql_insert_id();
			
			mysql_query("UPDATE `xine_discussions` SET `replys_count`= `replys_count` + 1, `last_reply_by`='$author', `last_reply_time`='$time' WHERE `id`='$did' LIMIT 1");
			
			return array('id' => $id, 'text' => $text, 'time' => $time, 'author' => $author);
		} else {
			return false;
		}
	}
} 